package com.zkk.dao.impl;

import com.zkk.dao.AdminDao;
import com.zkk.pojo.Admin;
import com.zkk.utils.DruidUtil;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class AdminDaoImpl implements AdminDao {
    private JdbcTemplate jdbcTemplate  = new JdbcTemplate(DruidUtil.getDataSource());
    @Override
    public Admin login(Admin admin) {
        List<Admin> query = jdbcTemplate.query("select * from admin where username= ? and password=?", new BeanPropertyRowMapper<>(Admin.class), admin.getUsername(), admin.getPassword());
        if (query!=null&&query.size()==1){
            return query.get(0);
        }
        return null;
    }

    @Override
    public List<Admin> findAll() {
        List<Admin> query = jdbcTemplate.query("select * from admin", new BeanPropertyRowMapper<>(Admin.class));
        return query;
    }
}
